//
//  PEPowerLoadPieCell.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/12/7.
//

#import "RHDeviceLoadPieCell.h"
#import "RHDeviceLoadPieChartView.h"
@interface RHDeviceLoadPieCell()

@property (nonatomic ,strong)RHDeviceLoadPieChartView *pieChartView;

@end
@implementation RHDeviceLoadPieCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setupUI];
    }
    return self;
}

-(void)setChartModel:(DevChartModel *)chartModel
{
    _chartModel = chartModel;
    self.pieChartView.chartModel = chartModel;
}
-(void)setLoadDic:(NSDictionary *)loadDic
{
    _loadDic = loadDic;
    _pieChartView.loadDic = loadDic;
}

- (void)setupUI{
    self.backgroundColor = UIColor.clearColor;
    [self.contentView setBackgroundColor:UIColor.clearColor];
    
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = UIColor.whiteColor;
    [bgView.layer setCornerRadius:8];
    bgView.layer.masksToBounds = YES;
    [self.contentView addSubview:bgView];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 15, 0, 15));
    }];
    
    //------------------------
    
    
    NSInteger type = 2;
    if ([self.reuseIdentifier containsString:@"Month"]) {
        type = 1;
    }
    if ([self.reuseIdentifier containsString:@"Day"]) {
        type = 2;
    }
    if ([self.reuseIdentifier containsString:@"Year"]) {
        type = 0;
    }
    _pieChartView = [[RHDeviceLoadPieChartView alloc] initWithFrame:CGRectMake(5, 5,SCREEN_WIDTH-40, 250+130) type:type];
    _pieChartView.layer.cornerRadius = 8;
    _pieChartView.layer.masksToBounds = YES;
    _pieChartView.backgroundColor = [UIColor whiteColor];
    [bgView addSubview:_pieChartView];
    
    
    kWeakSelf;
    _pieChartView.fullChartBlock = ^{
        if (weakSelf.fullChartBlock) {
            weakSelf.fullChartBlock();
        }
    };
    _pieChartView.selectTopToolBlock = ^(NSInteger index) {
        if (weakSelf.selectTopToolBlock) {
            weakSelf.selectTopToolBlock(index);
        }
    };
    
    _pieChartView.subTimeBlock = ^{//日期往前
        if (weakSelf.subTimeBlock) {
            weakSelf.subTimeBlock();
        }
    };
    
    _pieChartView.addTimeBlock = ^{//日期往后
        if (weakSelf.addTimeBlock) {
            weakSelf.addTimeBlock();
        }
    };
    
    _pieChartView.changeTimeBlock = ^{
        if (weakSelf.changeTimeBlock) {
            weakSelf.changeTimeBlock();
        }
    };
    
    
    [_pieChartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(5);
        make.right.mas_offset(-5);
        make.top.mas_offset(0);
        make.bottom.mas_offset(0);
        make.height.mas_equalTo(kUI_WINDOW_W*0.6+100);
    }];
}

@end
